﻿/* SessionHelper
 */

/*待测试*/
namespace LSLib.Web
{
    using System.Web;

    public static class SessionHelper
    {
        /// <summary>添加Session，调动有效期为20分钟
        /// </summary>
        /// <param name="sessionName">Session对象名称</param>
        /// <param name="values">Session值数组</param>
        public static void AddSession(string sessionName, params string[] values)
        {
            AddSession(20, sessionName, values);
        }
        /// <summary>添加Session
        /// </summary>
        /// <param name="iExpires">调动有效期（分钟）</param>
        /// <param name="sessionName">Session对象名称</param>
        /// <param name="values">Session值数组</param>
        public static void AddSession(int iExpires, string sessionName, params string[] values)
        {
            HttpContext.Current.Session[sessionName] = values;
            HttpContext.Current.Session.Timeout = iExpires;
        }

        /// <summary>读取某个Session对象值
        /// </summary>
        /// <param name="sessionName">Session对象名称</param>
        /// <returns>Session对象值</returns>
        public static string GetSession(string sessionName)
        {
            var obj = HttpContext.Current.Session[sessionName];
            if (obj == null) return null;
            return obj.ToString();
        }

        /// <summary>读取某个Session对象值数组
        /// </summary>
        /// <param name="sessionName">Session对象名称</param>
        /// <returns>Session对象值数组</returns>
        public static string[] GetSessions(string sessionName)
        {
            var obj = HttpContext.Current.Session[sessionName];
            if (obj == null) return null;
            return (string[])obj;
        }

        /// <summary>删除某个Session对象
        /// </summary>
        /// <param name="sessionName">Session对象名称</param>
        public static void Remove(string sessionName)
        {
            HttpContext.Current.Session[sessionName] = null;
        }
    }
}